package sg.edu.nus.iss.cats.controller;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LogoutServlet extends HttpServlet {

   public void doGet(HttpServletRequest request,HttpServletResponse response)
            throws ServletException, IOException {
            
            doPost(request,response);
            
   }
            
            
    public void doPost(HttpServletRequest request,HttpServletResponse response)
            throws ServletException, IOException {
    
        // Extract attributes we will need
        HttpSession session = request.getSession();
        UserSession userSession = (UserSession)session.getAttribute("USERSESSION");
        java.util.logging.Logger.getLogger(userSession.getClass().getName()).log(java.util.logging.Level.INFO,"user session is initialised");
        session.removeAttribute("USERSESSION");
        session.invalidate();
        
        //Forward to page which lists users
        RequestDispatcher rd = getServletContext().getRequestDispatcher( 
               "/index.jsp");

        if (rd != null){
           rd.forward(request,response);
        }
        
    }
    
        

}